﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FileMS
{
    public partial class Frm_FileMain : Form
    {
        public Frm_FileMain()
        {
            InitializeComponent();
        }

        #region  公共变量
        ModuleClass.FrmAffairClass FrmAClass = new FileMS.ModuleClass.FrmAffairClass();//实例化ModuleClass文件夹下的FrmAffairClass公共类
        ModuleClass.DataClass dataclass = new FileMS.ModuleClass.DataClass();//实例化ModuleClass文件夹下的DataClass公共类
        #endregion

        #region 调用Login及初始化
        private void Frm_FileMain_Load(object sender, EventArgs e)
        {
            Frm_Login FrmLogin = new Frm_Login();//实例化Frm_Login窗体
            FrmAClass.FrmSetUp(FrmLogin);//调用自定义方法FrmSetUp，对Frm_Login窗体进行设置
            if (FrmLogin.ShowDialog() == DialogResult.OK)//显示窗体
                strip_left_button_List_Click(sender, e);
          //  splitContainer.Dock = DockStyle.Fill;
        }
        #endregion

        private void splitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            listView_List.Columns[0].Width = splitContainer.Panel1.Width - 3;
        }

        private void strip_left_button_List_Click(object sender, EventArgs e)
        {
            FrmAClass.TreeAndList(listView_List, treeView_File, true);
            MainMenu_Vol_Manage.Enabled = true;
            MainMenu_File_Manage.Enabled = false;
            strip_left_button_Find.Visible = false;
            MainMenu_Find.Enabled = false;
            strip_left_text.Text = "资料集列表   ";
        }

        private void strip_left_button_File_Click(object sender, EventArgs e)
        {
            FrmAClass.TreeAndList(listView_List, treeView_File, false);
            MainMenu_Vol_Manage.Enabled = false;
            MainMenu_File_Manage.Enabled = true;
            strip_left_button_Find.Visible = true;
            MainMenu_Find.Enabled = true;
            strip_left_text.Text = "文件夹列表   ";
        }

        private void listView_List_DoubleClick(object sender, EventArgs e)
        {
            if (listView_List.SelectedItems != null)
            {
                FileMS.ModuleClass.FrmAffairClass.BaseNode = listView_List.SelectedItems[0].SubItems[0].Text.Trim();
                FrmAClass.ShowTree(treeView_File, FileMS.ModuleClass.FrmAffairClass.BaseNode);
                strip_left_button_File_Click(sender, e);
            }
        }

        private void treeView_File_AfterExpand(object sender, TreeViewEventArgs e)
        {
            FrmAClass.ADD_TreeNode(treeView_File, e.Node);
            e.Node.ImageIndex = 1;
        }

     /*   private void treeView_File_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ((TreeView)sender).SelectedNode = ((TreeView)sender).GetNodeAt(e.X, e.Y);
            }
            e.Node.SelectedImageIndex = e.Node.ImageIndex;
            FrmAClass.Show_AllFile(int.Parse(e.Node.Tag.ToString()), e.Node.Text, listView_All, 0);
            FileMS.ModuleClass.FrmAffairClass.Redact_N = "";
            FileMS.ModuleClass.FrmAffairClass.Redact_N = e.Node.Text;
            FileMS.ModuleClass.FrmAffairClass.Redact_M = e.Node.Tag.ToString();
            FileMS.ModuleClass.FrmAffairClass.BaseNode = "";
        }*/

        private void treeView_File_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            e.Node.ImageIndex = 0;
        }

        private void listView_All_DoubleClick(object sender, EventArgs e)
        {
            FrmAClass.Show_AllFile(int.Parse(((ListView)sender).SelectedItems[0].Tag.ToString()), ((ListView)sender).SelectedItems[0].Text, listView_All, 2);
        }

        private void Frm_FileMain_Shown(object sender, EventArgs e)
        {
            FrmAClass.FrmSetUp(this);//调用自定义方法FrmSetUp，对当前窗体进行设置
        }

        private void MainMenu_FolderM_Add_Click(object sender, EventArgs e)
        {
            if (treeView_File.SelectedNode != null && treeView_File.Visible == true)
            {
                FrmAClass.FolderEdit_form("F", treeView_File, int.Parse(((ToolStripMenuItem)sender).Tag.ToString()));
            }
        }

        #region 主菜单文件管理
        private void MainMenu_FolderM_Amend_Click(object sender, EventArgs e)
        {
            MainMenu_FolderM_Add_Click(sender, e);
        }

        private void MainMenu_FolderM_Delete_Click(object sender, EventArgs e)
        {
            MainMenu_FolderM_Amend_Click(sender, e);
        }

        private void MainMenu_FileM_Add_Click(object sender, EventArgs e)
        {
            if (treeView_File.SelectedNode != null)
            {
                FrmAClass.FileEdit_form("W", treeView_File, int.Parse(((ToolStripMenuItem)sender).Tag.ToString()));
            }
        }

        private void MainMenu_FileM_Amend_Click(object sender, EventArgs e)
        {
            MainMenu_FileM_Add_Click(sender, e);
        }

        private void MainMenu_FileM_Delete_Click(object sender, EventArgs e)
        {
            MainMenu_FileM_Add_Click(sender, e);
        }

        private void MainMenu_Import_Dir_Click(object sender, EventArgs e)
        {
            if (treeView_File.SelectedNode != null)
            {
                FrmAClass.GuideEdit_form("G", treeView_File, int.Parse(((ToolStripMenuItem)sender).Tag.ToString()));
            }
        }

        private void MainMenu_Export_Dir_Click(object sender, EventArgs e)
        {
            MainMenu_Import_Dir_Click(sender, e);
        }

        private void MainMenu_Export_File_Click(object sender, EventArgs e)
        {
            MainMenu_Import_Dir_Click(sender, e);
        }
        #endregion
        
        private void treeView_File_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            FrmAClass.Show_AllFile(int.Parse(e.Node.Tag.ToString()), e.Node.Text, listView_All, 2);
        }

        private void MainMenu_System_UserM_Click(object sender, EventArgs e)
        {
            TransferForm.F_User FrmUser = new FileMS.TransferForm.F_User();
            FrmAClass.FrmSetUp(FrmUser);//调用自定义方法FrmSetUp，对FrmUser窗体进行设置
            FrmUser.ShowDialog();//显示窗体
        }

        private void strip_left_button_Find_Click(object sender, EventArgs e)
        {
            //   if (tool_text.Text == "文件夹列表   ")
            panel_Find.Visible = !panel_Find.Visible;
        }

        private void textBox_FName_KeyPress(object sender, KeyPressEventArgs e)
        {
            FrmAClass.Files_NameChar(e);//不显示文件名禁止使用的字符
        }

        private void File_Find_Click(object sender, EventArgs e)
        {
            FrmAClass.Find_File(treeView_File, listView_All, textBox_FName.Text.Trim());//查找文件
        }

        private void ContextMenu_DataAdd_Click(object sender, EventArgs e)
        {
            FrmAClass.FolderEdit_form("T", listView_List, int.Parse(((ToolStripMenuItem)sender).Tag.ToString()));
        }

        private void ContextMenu_DataAmend_Click(object sender, EventArgs e)
        {
            if (listView_List.SelectedItems.Count > 0)
                ContextMenu_DataAdd_Click(sender, e);
        }

        private void ContextMenu_DataDelete_Click(object sender, EventArgs e)
        {
            ContextMenu_DataAmend_Click(sender, e);
        }

        private void MainMenu_Vol_Add_Click(object sender, EventArgs e)
        {
            if (listView_List.Visible)
                ContextMenu_DataAdd_Click(sender, e);
        }

        private void MainMenu_Vol_Amend_Click(object sender, EventArgs e)
        {
            if (listView_List.Focused)
                ContextMenu_DataAmend_Click(sender, e);
        }

        private void MainMenu_Vol_Delete_Click(object sender, EventArgs e)
        {
            if (listView_List.Focused)
                ContextMenu_DataDelete_Click(sender, e);
        }
    }
}